
import {
  queryPromotionOrderList
} from "../../../../service/jb_promotion_service"
import {
  queryPersonCheckList, // oa大学生身份认证列表 
  checkPersonReq,        //oa审核大学生身份
} from "../../../../service/jb_activity_service"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    topSwiperIndex: 0,
    page: 1,
    limit: 20,
    dataList: [

    ],
    totalCount: 0,
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
    showRefundPop: false,
    currentItem: {},
    currentIndex: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryPromotionOrderList('refresh');

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  createActivityAction() {
    wx.navigateTo({
      url: '/featurePackage/pages/oaManager/createActivity/createActivity',
    })
  },
  queryPromotionOrderList(type) {
    wx.showLoading();
    queryPersonCheckList(this.data.page, this.data.limit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          totalCount: res.data.count,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
      console.error('JJLog:queryPromotionOrderList', err);
    })
  },

  //下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryPromotionOrderList('refresh');
  },
  handleLoadmore() {
    console.log('加载更多');
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.queryPromotionOrderList()
  },
  //通过
  agreeAction(e) {
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '提示',
      content: '确认通过认证?',
      confirmColor: "#ff0000",
      success: res => {
        if (res.confirm) {
          let req = {
            id: item.id,
            examineStatus: 1,
          }
          wx.showLoading();
          checkPersonReq(req).then(res => {
            wx.hideLoading();
            if (res.code == 200) {
              wx.showToast({
                title: '操作成功',
                icon: "success"
              })
              let arr = this.data.dataList;
              arr.splice(index, 1);
              this.setData({
                dataList: arr,
              })
            }
          }).catch(err => {
            wx.hideLoading();
            wx.showToast({
              title: err || "操作失败",
              icon: "none"
            })
            console.error("JJLog:checkWorksReq", err);
          })
        }

      }
    })
  },
  //拒绝
  refunseAction(e) {
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    this.setData({
      showRefundPop: true,
      currentItem: item,
      currentIndex: index
    })
  },
  refundSureAction(e) {
    let valueText = e.detail.comment;
    let req = {

      id: this.data.currentItem.id,
      examineStatus: 2,
      examineRemark: valueText,
    }
    wx.showLoading();
    checkPersonReq(req).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        wx.showToast({
          title: '操作成功',
          icon: "success"
        })
        this.setData({
          showRefundPop: false
        })
        let arr = this.data.dataList;
        arr.splice(this.data.currentIndex, 1);
        this.setData({
          dataList: arr,
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:checkWorksReq", err);
    })
  },
  refundPopHide() {
    this.setData({
      showRefundPop: false
    })
  },


})